

jQuery(function ($) {  
    var user = JSON.parse(localStorage.getItem('user_info')) || {};
    var userId = user.id;
    var onoff = false;
    //搜索关键字请求接口渲染页面数据
    var keyword = decodeURIComponent(window.location.href.split('=')[1]);
    if (keyword != 'undefined') {
        $('#location').append('<h1>' + keyword + '</h1>');
        $('#search').attr('value', keyword);
    }
    var page = 0;
    //导航栏关键字
    getList(page);
    //分页按钮
    var pageOnOff = true;
    function twbsPagination( totalPage) {
        Page({
			num:Math.ceil(totalPage / 20),					//页码数
			startnum:1,				//指定页码
			elem:$('#pagination_b'),		//指定的元素
			callback:function(page){	//回调函数
                if (page != 1) {
                    onoff = true;
                }
                if (onoff) {
                    $('.works_show').empty();
                    getList(page - 1);
                    $('html,body').animate({scrollTop:$('.s_content ').offset().top-80}, 500);
                }
			}
		});


    };
    function getList(page) {
        var data = {
            pageNum: page,
            pageSize: 20,
            userId:userId
        };
        if (keyword != "") {
            data.keyword = keyword;
        }
        $.ajax({
            type: "GET",
            url: search_url + '/search/goods',
            data: data,
            success: function success(res) {
                if (res.code == 200) {
                    var res = res.data;
                    if (res.list.length == 0) {
                        $('.works_show').append('<h3>\u6CA1\u6709\u6570\u636E</h3>');
                    } else {
                        $('.s_nav_right').empty();
                        $('.s_nav_right').append('<span>\u5171\u6709<span>' + res.total + '</span> \u5E45\u5B57\u753B</span>\n');
                        var html="";
                        for (var i = 0; i < res.list.length; i++) {
                            var splitLength = res.list[i].goodsAdNameStyle.split('+');
                            if(splitLength[1] !=''&&splitLength[0] !=''){
                                res.list[i].goodsAdName = '<'+splitLength[1]+' style="color:'+splitLength[0]+'">'+res.list[i].goodsAdName+'</'+splitLength[1]+'>'
                            };
                            if(splitLength[1] !=''&&splitLength[0] ==''){
                                res.list[i].goodsAdName = '<'+splitLength[1]+'>'+res.list[i].goodsAdName+'</'+splitLength[1]+'>'
                            };
                            if(splitLength[1] ==''&&splitLength[0] !=''){
                                res.list[i].colorOnOff = true;
                            };
                            res.list[i]['mainFlagImgList'] = [];
                            if(res.list[i].imgsList.length > 0){
                                for(var mi = 0; mi < res.list[i].imgsList.length; mi++){
                                    if(res.list[i].imgsList[mi].mainFlag > 0){
                                        res.list[i]['mainFlagImgList'].push(res.list[i].imgsList[mi]);
                                    }
                                }
                            }
                            html+= '<li class="works_show_item" data-id="' + res.list[i].id + '" data-title="' + res.list[i].name + '" data-url="http://static.yczihua.com/images/201802/thumb_img/9638_thumb_G_1517523720728.jpg" data-price="\xA5' + res.list[i].goodsPrice + '" data-txt="\u610F\u5883\u4F18\u7F8E">\n                                <div class="works_show_pic">\n  <a href="/goods-' + res.list[i].id + '.html" target="_blank"><img src="' + isImgHttp(res.list[i].mainFlagImgList[0].thumb) + '"></img></a> \n                                    <i class="goods_status1  ' + (res.list[i].goodsStatus.goodsStatus == 6 ? 'open' : 'hide') + ' g_status"></i> <i class="goods_status2 ' + (res.list[i].goodsStatus.goodsStatus == 5 ? 'open' : 'hide') + ' g_status"></i> <i class="goods_status3 ' + (res.list[i].goodsStatus.goodsStatus == 4 ? 'open' : 'hide') + ' g_status" ></i> <i class="goods_status4  ' + (res.list[i].goodsStatus == 1 ? 'open' : 'hide') + ' g_status" ></i> <i class="goods_status5 ' + (res.list[i].goodsStatus == 3? 'open' : 'hide') + ' g_status" ></i> <i class="goods_status6  ' + (res.list[i].goodsStatus == 2 ? 'open' : 'hide') + ' g_status" ></i>\n                                </div>\n                                <div class="works_show_item_msg">\n                                    <div class="works_show_price">\n                                        <span>\xA5' + res.list[i].goodsStatus.price + '</span>\n                                    </div>\n                                    <div class="works_show_pic_introduce">\n                                        <p class="pic_msg">\n<a href="/goods-' + res.list[i].id + '.html" target="_blank" class="goodsBox"> <span class="title">' + res.list[i].name + '</span>\n<span class="special_txt" style="color:'+ (res.list[i].colorOnOff?splitLength[0]:'')+'">' + res.list[i].goodsAdName + '</span></a>\n                                        </p>\n                                        <p class="soldoutNum">\u6B64\u540D\u5BB6\u8FD130\u5929\u5DF2\u552E<span class="works_show_pic_m">'+(res.list[i].artistSoldNum?res.list[i].artistSoldNum:0)+'</span>幅</p>\n                                    </div>\n                                    <div class="hall_of_fame">\n <a class="  ' + (res.list[i].goodsStatus.hofFlag? 'halloffame' : 'hide') + '">\u540D\u4EBA\u5802</a>\n <a class="hide">\u81EA\u8425</a>\n  </div>\n                                    <!-- <div class="concession_coupon">\n                                            <a>\u4F18\u60E0</a>\n                                            <a>\u9886\u523850-200</a>\n                                        </div> -->\n                                    <ul class="works_show_item_bottom">\n                                        <li class="item contrast_box">\n                                            <span class="contrast"></span>\n                                            <span>\u5BF9\u6BD4</span>\n                                        </li>\n                                        <li class="item collect_box">\n                                            <i class="collect"></i>\n                                            <span>\u6536\u85CF</span>\n                                        </li>\n                                        <li class="item join_car ' + ((res.list[i].goodsStatus.goodsStatus ==1 ||res.list[i].goodsStatus.goodsStatus ==2 || res.list[i].goodsStatus.goodsStatus==3||res.list[i].goodsStatus.goodsStatus==7)? 'show' : 'hide') + '">\n<i class="s_cart"></i>\n<span>\u52A0\u5165\u8D2D\u7269\u8F66</span>\n</li>\n<li class="items ' + ((res.list[i].goodsStatus.goodsStatus==4)? 'show' : 'hide') + '">\n<i></i>\n <a href="http://114.116.69.140:8888/dialog_1.htm" target="_blank"><span class="my_customized">作品定制</span></a>\n</li>\n<li class="noJoin ' + ((res.list[i].goodsStatus.goodsStatus==5)? 'show' : 'hide') + '">\n<i></i>\n   <a href="http://114.116.69.140:8888/dialog_1.htm" class="previews attr" target="_blank">作品欣赏</a>\n</li>\n<li class="noJoin '  + ((res.list[i].goodsStatus.goodsStatus==6)?'show' : 'hide') + '">\n<i></i>\n<a href="http://114.116.69.140:8888/dialog_1.htm" class="soldOut attr" target="_blank">作品已售</a>\n</li>\n</ul>\n</div>\n</li>';

                            $('.works_show').html(html);
                        }
                        if (pageOnOff) {
                            //分页按钮
                            twbsPagination(res.total);
                            pageOnOff=false;
                        }
                    }
                }
            }
        });
    };
  
});